#include <iostream>
#include <signal.h>
#include <unistd.h>

using namespace std;


void handler(int signum)
{
    cout<<"received signal "<<signum<<endl;
    if(signum==SIGALRM) alarm(5);   // 如果是SIGALRM信号，则重新设置alarm
}


int main()
{
    signal(SIGALRM,handler);
    alarm(5);
    while(true)
    {
        cout<<"process is running... "<<endl;
        sleep(1);
    }
    return 0;
}